using FluentValidation.Results;

namespace Zhaoxi.Zhihu.UseCases.Common.Exceptions;

public class ValidationException(): Exception("发生了一个或多个验证失败")
{
    public ValidationException(IEnumerable<ValidationFailure> failures) : this()
    {
        Errors = failures
            .GroupBy(x => x.PropertyName, x => x.ErrorMessage)
            .ToDictionary(g => g.Key, g => g.ToArray());
    }
    
    public IDictionary<string, string[]> Errors { get; set; }=new Dictionary<string, string[]>();
}